Python 字符串

时间:2026-04-21 来源:

字符串字面量

python 中的字符串字面量由单引号或双引号括起。

'hello' 等同于 "hello"。

您可以使用 print() 函数显示字符串字面量:


print("Hello")

print('Hello')


用字符串向变量赋值

通过使用变量名称后跟等号和字符串,可以把字符串赋值给变量:


a = "Hello"

print(a)


多行字符串

您可以使用三个引号将多行字符串赋值给变量:

实例

您可以使用三个双引号,或三个单引号:


a = """Python is a widely used general-purpose, high level programming language.
It was initially designed by Guido van Rossum in 1991
and developed by Python Software Foundation.
It was mainly developed for emphasis on code readability,
and its syntax allows programmers to express concepts in fewer lines of code."""

print(a)

相关文章: